

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>3.2. Native contacts analysis — MDAnalysis.analysis.contacts &mdash; MDAnalysis v0.7.5-devel documentation</title>
    <link rel="stylesheet" href="../../_static/sphinxdoc.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '0.7.5-devel',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <link rel="search" type="application/opensearchdescription+xml"
          title="Search within MDAnalysis v0.7.5-devel documentation"
          href="../../_static/opensearch.xml"/>
    <link rel="shortcut icon" href="../../_static/mdanalysis-logo.ico"/>
    <link rel="top" title="MDAnalysis v0.7.5-devel documentation" href="../../index.html" />
    <link rel="up" title="3. Analysis modules" href="../analysis_modules.html" />
    <link rel="next" title="3.3. Distance analysis — MDAnalysis.distances" href="distances.html" />
    <link rel="prev" title="3.1. Coordinate fitting and alignment — MDAnalysis.analysis.align" href="align.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="distances.html" title="3.3. Distance analysis — MDAnalysis.distances"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="align.html" title="3.1. Coordinate fitting and alignment — MDAnalysis.analysis.align"
             accesskey="P">previous</a> |</li>
        <li><a href="../../index.html">MDAnalysis v0.7.5-devel documentation</a> &raquo;</li>
          <li><a href="../analysis_modules.html" accesskey="U">3. Analysis modules</a> &raquo;</li> 
      </ul>
    </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../../index.html">
              <img class="logo" src="../../_static/mdanalysis-logo-200x150.png" alt="Logo"/>
            </a></p>
  <h3><a href="../../index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">3.2. Native contacts analysis &#8212; <tt class="docutils literal"><span class="pre">MDAnalysis.analysis.contacts</span></tt></a><ul>
<li><a class="reference internal" href="#examples">3.2.1. Examples</a><ul>
<li><a class="reference internal" href="#one-dimensional-contact-analysis">3.2.1.1. One-dimensional contact analysis</a></li>
<li><a class="reference internal" href="#two-dimensional-contact-analysis-q1-q2">3.2.1.2. Two-dimensional contact analysis (q1-q2)</a></li>
</ul>
</li>
<li><a class="reference internal" href="#classes">3.2.2. Classes</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="align.html"
                        title="previous chapter">3.1. Coordinate fitting and alignment &#8212; <tt class="docutils literal"><span class="pre">MDAnalysis.analysis.align</span></tt></a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="distances.html"
                        title="next chapter">3.3. Distance analysis &#8212; <tt class="docutils literal"><span class="pre">MDAnalysis.distances</span></tt></a></p>
  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="../../_sources/documentation_pages/analysis/contacts.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" size="18" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <span class="target" id="module-MDAnalysis.analysis.contacts"></span><div class="section" id="native-contacts-analysis-mdanalysis-analysis-contacts">
<h1>3.2. Native contacts analysis &#8212; <a class="reference internal" href="#module-MDAnalysis.analysis.contacts" title="MDAnalysis.analysis.contacts"><tt class="xref py py-mod docutils literal"><span class="pre">MDAnalysis.analysis.contacts</span></tt></a><a class="headerlink" href="#native-contacts-analysis-mdanalysis-analysis-contacts" title="Permalink to this headline">¶</a></h1>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Author:</th><td class="field-body">Oliver Beckstein</td>
</tr>
<tr class="field"><th class="field-name">Year:</th><td class="field-body">2010</td>
</tr>
<tr class="field"><th class="field-name">Copyright:</th><td class="field-body">GNU Public License v3</td>
</tr>
</tbody>
</table>
<p>Analysis of native contacts <em>q</em> over a trajectory.</p>
<ul class="simple">
<li>a &#8220;contact&#8221; exists between two atoms <em>i</em> and <em>j</em> if the distance between them is
smaller than a given <em>radius</em></li>
<li>a &#8220;native contact&#8221; exists between <em>i</em> and <em>j</em> if a contact exists and if the
contact also exists between the equivalent atoms in a reference structure or
conformation</li>
</ul>
<p>The &#8220;fraction of native contacts&#8221; <em>q(t)</em> is a number between 0 and 1 and
calculated as the total number of native contacts for a given time frame
divided by the total number of contacts in the reference structure.</p>
<p>Classes are available for two somewhat different ways to perform a contact
analysis:</p>
<ol class="arabic simple">
<li>Contacts between two groups of atoms are defined with
<a class="reference internal" href="#MDAnalysis.analysis.contacts.ContactAnalysis1" title="MDAnalysis.analysis.contacts.ContactAnalysis1"><tt class="xref py py-class docutils literal"><span class="pre">ContactAnalysis1</span></tt></a>), which allows one to calculate <em>q(t)</em> over
time. This is especially useful in order to look at native contacts during
an equilibrium simulation where one can also look at the average matrix of
native contacts (see <a class="reference internal" href="#MDAnalysis.analysis.contacts.ContactAnalysis1.plot_qavg" title="MDAnalysis.analysis.contacts.ContactAnalysis1.plot_qavg"><tt class="xref py py-meth docutils literal"><span class="pre">ContactAnalysis1.plot_qavg()</span></tt></a>).</li>
<li>Contacts are defined within one group in a protein (e.g. all C-alpha atoms)
but relative to <em>two different conformations</em> 1 and 2, using
<a class="reference internal" href="#MDAnalysis.analysis.contacts.ContactAnalysis" title="MDAnalysis.analysis.contacts.ContactAnalysis"><tt class="xref py py-class docutils literal"><span class="pre">ContactAnalysis</span></tt></a>. This allows one to do a <em>q1-q2</em> analysis that
shows how native contacts of state 1 change in comparison to native contacts
of state 2.  Transition pathways have been analyzed in terms of these two
variables q1 and q2 that relate to the native contacts in the end states of
the transition.</li>
</ol>
<div class="admonition-see-also admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last">See <a class="reference external" href="http://lorentz.dynstr.pasteur.fr/joel/adenylate.php">http://lorentz.dynstr.pasteur.fr/joel/adenylate.php</a> for an
example of contact analysis applied to MinActionPath trajectories of AdK
(although this was <em>not</em> performed with MDAnalysis &#8212; it&#8217;s provided as a
very good illustrative example).</p>
</div>
<div class="section" id="examples">
<h2>3.2.1. Examples<a class="headerlink" href="#examples" title="Permalink to this headline">¶</a></h2>
<div class="section" id="one-dimensional-contact-analysis">
<h3>3.2.1.1. One-dimensional contact analysis<a class="headerlink" href="#one-dimensional-contact-analysis" title="Permalink to this headline">¶</a></h3>
<p>As an example we analyze the opening (&#8220;unzipping&#8221;) of salt bridges
when the AdK enzyme opens up; this is one of the example trajectories
in MDAnalysis.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">MDAnalysis</span>
<span class="kn">import</span> <span class="nn">MDAnalysis.analysis.contacts</span>
<span class="kn">from</span> <span class="nn">MDAnalysis.tests.datafiles</span> <span class="kn">import</span> <span class="n">PSF</span><span class="p">,</span><span class="n">DCD</span>

<span class="c"># example trajectory (transition of AdK from closed to open)</span>
<span class="n">u</span> <span class="o">=</span> <span class="n">MDAnalysis</span><span class="o">.</span><span class="n">Universe</span><span class="p">(</span><span class="n">PSF</span><span class="p">,</span><span class="n">DCD</span><span class="p">)</span>

<span class="c"># crude definition of salt bridges as contacts between NH/NZ in ARG/LYS and OE*/OD* in ASP/GLU.</span>
<span class="c"># You might want to think a little bit harder about the problem before using this for real work.</span>
<span class="n">sel_basic</span> <span class="o">=</span> <span class="s">&quot;(resname ARG or resname LYS) and (name NH* or name NZ)&quot;</span>
<span class="n">sel_acidic</span> <span class="o">=</span> <span class="s">&quot;(resname ASP or resname GLU) and (name OE* or name OD*)&quot;</span>

<span class="c"># reference groups (first frame of the trajectory, but you could also use a separate PDB, eg crystal structure)</span>
<span class="n">acidic</span> <span class="o">=</span> <span class="n">u</span><span class="o">.</span><span class="n">selectAtoms</span><span class="p">(</span><span class="n">sel_acidic</span><span class="p">)</span>
<span class="n">basic</span> <span class="o">=</span> <span class="n">u</span><span class="o">.</span><span class="n">selectAtoms</span><span class="p">(</span><span class="n">sel_basic</span><span class="p">)</span>

<span class="c"># set up analysis of native contacts (&quot;salt bridges&quot;); salt bridges have a distance &lt;6 A</span>
<span class="n">CA1</span> <span class="o">=</span> <span class="n">MDAnalysis</span><span class="o">.</span><span class="n">analysis</span><span class="o">.</span><span class="n">contacts</span><span class="o">.</span><span class="n">ContactAnalysis1</span><span class="p">(</span><span class="n">u</span><span class="p">,</span> <span class="n">selection</span><span class="o">=</span><span class="p">(</span><span class="n">sel_acidic</span><span class="p">,</span> <span class="n">sel_basic</span><span class="p">),</span> <span class="n">refgroup</span><span class="o">=</span><span class="p">(</span><span class="n">acidic</span><span class="p">,</span> <span class="n">basic</span><span class="p">),</span> <span class="n">radius</span><span class="o">=</span><span class="mf">6.0</span><span class="p">,</span> <span class="n">outfile</span><span class="o">=</span><span class="s">&quot;qsalt.dat&quot;</span><span class="p">)</span>

<span class="c"># iterate through trajectory and perform analysis of &quot;native contacts&quot; q</span>
<span class="c"># (force=True ignores any previous results, force=True is useful when testing)</span>
<span class="n">CA1</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">force</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>

<span class="c"># plot time series q(t) [possibly do &quot;import pylab; pylab.clf()&quot; do clear the figure first...]</span>
<span class="n">CA1</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">filename</span><span class="o">=</span><span class="s">&quot;adk_saltbridge_contact_analysis1.pdf&quot;</span><span class="p">,</span> <span class="n">linewidth</span><span class="o">=</span><span class="mi">3</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="s">&quot;blue&quot;</span><span class="p">)</span>

<span class="c"># or plot the data in qsalt.dat yourself.</span>
<span class="n">CA1</span><span class="o">.</span><span class="n">plot_qavg</span><span class="p">(</span><span class="n">filename</span><span class="o">=</span><span class="s">&quot;adk_saltbridge_contact_analysis1_matrix.pdf&quot;</span><span class="p">)</span>
</pre></div>
</div>
<p>The first graph shows that when AdK opens, about 20% of the salt
bridges that existed in the closed state disappear when the enzyme
opens. They open in a step-wise fashion (made more clear by the movie
<a class="reference external" href="http://sbcb.bioch.ox.ac.uk/oliver/Movies/AdK/AdK_zipper_cartoon.avi">http://sbcb.bioch.ox.ac.uk/oliver/Movies/AdK/AdK_zipper_cartoon.avi</a>
(divx, on Mac use <a class="reference external" href="http://perian.org">http://perian.org</a>)).</p>
<p>The output graphs can be made prettier but if you look at the code
itself then you&#8217;ll quickly figure out what to do. The qavg plot is the
matrix of all contacts, averaged over the trajectory. This plot makes
more sense for an equilibrium trajectory than for the example above
but is is included for illustration.</p>
<p>See the docs for <a class="reference internal" href="#MDAnalysis.analysis.contacts.ContactAnalysis1" title="MDAnalysis.analysis.contacts.ContactAnalysis1"><tt class="xref py py-class docutils literal"><span class="pre">ContactAnalysis1</span></tt></a> for another example.</p>
</div>
<div class="section" id="two-dimensional-contact-analysis-q1-q2">
<h3>3.2.1.2. Two-dimensional contact analysis (q1-q2)<a class="headerlink" href="#two-dimensional-contact-analysis-q1-q2" title="Permalink to this headline">¶</a></h3>
<p>Analyze a single DIMS transition of AdK between its closed and open
conformation and plot the trajectory projected on q1-q2:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">MDAnalysis.analysis.contacts</span>
<span class="kn">from</span> <span class="nn">MDAnalysis.tests.datafiles</span> <span class="kn">import</span> <span class="o">*</span>
<span class="n">C</span> <span class="o">=</span> <span class="n">MDAnalysis</span><span class="o">.</span><span class="n">analysis</span><span class="o">.</span><span class="n">contacts</span><span class="o">.</span><span class="n">ContactAnalysis</span><span class="p">(</span><span class="n">PSF</span><span class="p">,</span> <span class="n">DCD</span><span class="p">)</span>
<span class="n">C</span><span class="o">.</span><span class="n">run</span><span class="p">()</span>
<span class="n">C</span><span class="o">.</span><span class="n">plot</span><span class="p">()</span>
</pre></div>
</div>
<p>Compare the resulting pathway to the <a class="reference external" href="http://lorentz.dynstr.pasteur.fr/joel/adenylate.php">MinActionPath result for AdK</a>.</p>
</div>
</div>
<div class="section" id="classes">
<h2>3.2.2. Classes<a class="headerlink" href="#classes" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="MDAnalysis.analysis.contacts.ContactAnalysis">
<em class="property">class </em><tt class="descclassname">MDAnalysis.analysis.contacts.</tt><tt class="descname">ContactAnalysis</tt><big>(</big><em>topology</em>, <em>trajectory</em>, <em>ref1=None</em>, <em>ref2=None</em>, <em>radius=8.0</em>, <em>targetdir='.'</em>, <em>infix=''</em>, <em>force=False</em><big>)</big><a class="headerlink" href="#MDAnalysis.analysis.contacts.ContactAnalysis" title="Permalink to this definition">¶</a></dt>
<dd><p>Perform a native contact analysis (&#8220;q1-q2&#8221;).</p>
<p>The analysis of the trajectory is performed with the
<a class="reference internal" href="#MDAnalysis.analysis.contacts.ContactAnalysis.run" title="MDAnalysis.analysis.contacts.ContactAnalysis.run"><tt class="xref py py-meth docutils literal"><span class="pre">ContactAnalysis.run()</span></tt></a> method. The result is stored in
<tt class="xref py py-attr docutils literal"><span class="pre">ContactAnalysis.timeseries</span></tt>. It is a numpy array which
contains the frame number at index 0, q1 and q2 at index 1 and 2,
and the total number of contacts in 3 and 4.</p>
<div class="highlight-python"><pre>frame  q1 q2  n1 n2</pre>
</div>
<p>The total number of contacts in the reference states 1 and 2 are
stored in <tt class="xref py py-attr docutils literal"><span class="pre">ContactAnalysis.nref</span></tt> (index 0 and 1).</p>
<p>Calculate native contacts from two reference structures.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Arguments :</th><td class="field-body"><dl class="first last docutils">
<dt><em>topology</em></dt>
<dd><p class="first last">psf or pdb file</p>
</dd>
<dt><em>trajectory</em></dt>
<dd><p class="first last">dcd or xtc/trr file</p>
</dd>
<dt><em>ref1</em></dt>
<dd><p class="first last">structure of the reference conformation 1 (pdb); if <tt class="xref docutils literal"><span class="pre">None</span></tt> the <em>first</em>
frame of the trajectory is chosen</p>
</dd>
<dt><em>ref2</em></dt>
<dd><p class="first last">structure of the reference conformation 2 (pdb); if <tt class="xref docutils literal"><span class="pre">None</span></tt> the <em>last</em>
frame of the trajectory is chosen</p>
</dd>
<dt><em>radius</em></dt>
<dd><p class="first last">contacts are deemed any Ca within radius [8 A]</p>
</dd>
<dt><em>targetdir</em></dt>
<dd><p class="first last">output files are saved there [.]</p>
</dd>
<dt><em>infix</em></dt>
<dd><p class="first last">additional tag string that is inserted into the output filename of the
data file [&#8220;&#8221;]</p>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
<p>The function calculates the percentage of native contacts q1 and q2
along a trajectory. &#8220;Contacts&#8221; are defined as the number of Ca atoms
within <em>radius</em> of a primary Ca. <em>q1</em> is the fraction of contacts
relative to the reference state 1 (typically the starting conformation
of the trajectory) and <em>q2</em> is the fraction of contacts relative to the
conformation 2.</p>
<p>The timeseries is written to a bzip2-compressed file in <em>targetdir</em>
named &#8220;basename(<em>trajectory</em>)*infix*_q1q2.dat.bz2&#8221; and is also
accessible as the attribute <tt class="xref py py-attr docutils literal"><span class="pre">ContactAnalysis.timeseries</span></tt>.</p>
<dl class="method">
<dt id="MDAnalysis.analysis.contacts.ContactAnalysis.load">
<tt class="descname">load</tt><big>(</big><em>filename</em><big>)</big><a class="headerlink" href="#MDAnalysis.analysis.contacts.ContactAnalysis.load" title="Permalink to this definition">¶</a></dt>
<dd><p>Load the data file.</p>
</dd></dl>

<dl class="method">
<dt id="MDAnalysis.analysis.contacts.ContactAnalysis.output_exists">
<tt class="descname">output_exists</tt><big>(</big><em>force=False</em><big>)</big><a class="headerlink" href="#MDAnalysis.analysis.contacts.ContactAnalysis.output_exists" title="Permalink to this definition">¶</a></dt>
<dd><p>Return True if default output file already exists.</p>
<p>Disable with force=True (will always return False)</p>
</dd></dl>

<dl class="method">
<dt id="MDAnalysis.analysis.contacts.ContactAnalysis.plot">
<tt class="descname">plot</tt><big>(</big><em>**kwargs</em><big>)</big><a class="headerlink" href="#MDAnalysis.analysis.contacts.ContactAnalysis.plot" title="Permalink to this definition">¶</a></dt>
<dd><p>Plot q1-q2.</p>
</dd></dl>

<dl class="method">
<dt id="MDAnalysis.analysis.contacts.ContactAnalysis.qN">
<tt class="descname">qN</tt><big>(</big><em>q</em>, <em>n</em>, <em>out=None</em><big>)</big><a class="headerlink" href="#MDAnalysis.analysis.contacts.ContactAnalysis.qN" title="Permalink to this definition">¶</a></dt>
<dd><p>Calculate native contacts relative to state n.</p>
<p>If <em>out</em> is supplied as a pre-allocated array of the correct
shape then it is filled instead of allocating a new one in
order to increase performance.</p>
</dd></dl>

<dl class="method">
<dt id="MDAnalysis.analysis.contacts.ContactAnalysis.qarray">
<tt class="descname">qarray</tt><big>(</big><em>d</em>, <em>out=None</em><big>)</big><a class="headerlink" href="#MDAnalysis.analysis.contacts.ContactAnalysis.qarray" title="Permalink to this definition">¶</a></dt>
<dd><p>Return distance array with True for contacts.</p>
<p>If <em>out</em> is supplied as a pre-allocated array of the correct
shape then it is filled instead of allocating a new one in
order to increase performance.</p>
</dd></dl>

<dl class="method">
<dt id="MDAnalysis.analysis.contacts.ContactAnalysis.run">
<tt class="descname">run</tt><big>(</big><em>store=True</em>, <em>force=False</em><big>)</big><a class="headerlink" href="#MDAnalysis.analysis.contacts.ContactAnalysis.run" title="Permalink to this definition">¶</a></dt>
<dd><p>Analyze trajectory and produce timeseries.</p>
<p>Stores results in <tt class="xref py py-attr docutils literal"><span class="pre">ContactAnalysis.timeseries</span></tt> (if
store=True) and writes them to a bzip2-compressed data file.</p>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="MDAnalysis.analysis.contacts.ContactAnalysis1">
<em class="property">class </em><tt class="descclassname">MDAnalysis.analysis.contacts.</tt><tt class="descname">ContactAnalysis1</tt><big>(</big><em>*args</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#MDAnalysis.analysis.contacts.ContactAnalysis1" title="Permalink to this definition">¶</a></dt>
<dd><p>Perform a very flexible native contact analysis with respect to a single reference.</p>
<dl class="class">
<dt id="MDAnalysis.analysis.contacts.ContactAnalysis1.ContactAnalysis1">
<em class="property">class </em><tt class="descname">ContactAnalysis1</tt><big>(</big><em>topology</em>, <em>trajectory</em><span class="optional">[</span>, <em>selection</em><span class="optional">[</span>, <em>refgroup</em><span class="optional">[</span>, <em>radius</em><span class="optional">[</span>, <em>outfile</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#MDAnalysis.analysis.contacts.ContactAnalysis1.ContactAnalysis1" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="class">
<dt>
<em class="property">class </em><tt class="descclassname">MDAnalysis.analysis.contacts.</tt><tt class="descname">ContactAnalysis1</tt><big>(</big><em>universe</em><span class="optional">[</span>, <em>selection</em><span class="optional">[</span>, <em>refgroup</em><span class="optional">[</span>, <em>radius</em><span class="optional">[</span>, <em>outfile</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><big>)</big></dt>
<dd></dd></dl>

<p>This analysis class allows one to calculate the fraction of native contacts
<em>q</em> between two arbitrary groups of atoms with respect to an arbitrary
reference structure. For instance, as a reference one could take a crystal
structure of a complex, and as the two groups atoms one selects two
molecules A and B in the complex. Then the question to be answered by <em>q</em>
is, is which percentage of the contacts between A and B persist during the simulation.</p>
<p>First prepare <a class="reference internal" href="../core/AtomGroup.html#MDAnalysis.core.AtomGroup.AtomGroup" title="MDAnalysis.core.AtomGroup.AtomGroup"><tt class="xref py py-class docutils literal"><span class="pre">AtomGroup</span></tt></a> selections for
the reference atoms; this example uses some arbitrary selections:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">ref</span> <span class="o">=</span> <span class="n">Universe</span><span class="p">(</span><span class="s">&#39;crystal.pdb&#39;</span><span class="p">)</span>
<span class="n">refA</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">selectAtoms</span><span class="p">(</span><span class="s">&#39;name CA and segid A and resid 6:100&#39;</span><span class="p">)</span>
<span class="n">refB</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">selectAtoms</span><span class="p">(</span><span class="s">&#39;name CA and segid B and resid 1:40&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>Load the trajectory:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">u</span> <span class="o">=</span> <span class="n">Universe</span><span class="p">(</span><span class="n">topology</span><span class="p">,</span> <span class="n">trajectory</span><span class="p">)</span>
</pre></div>
</div>
<p>We then need two selection strings <em>selA</em> and <em>selB</em> that, when applied as
<tt class="docutils literal"><span class="pre">u.selectAtoms(selA)</span></tt> produce a list of atoms that is equivalent to the
reference (i.e. <tt class="docutils literal"><span class="pre">u.selectAtoms(selA)</span></tt> must select the same atoms as
<tt class="docutils literal"><span class="pre">refA</span></tt> in this example):</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">selA</span> <span class="o">=</span> <span class="s">&#39;name CA and resid 1:95&#39;</span>     <span class="c"># corresponds to refA</span>
<span class="n">selB</span> <span class="o">=</span> <span class="s">&#39;name CA and resid 150:189&#39;</span>  <span class="c"># corresponds to refB</span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">It is the user&#8217;s responsibility to provide a reference group
(or groups) that describe equivalent atoms to the ones selected
by <em>selection</em>.</p>
</div>
<p>Now we are ready to set up the analysis:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">CA1</span> <span class="o">=</span> <span class="n">ContactAnalysis1</span><span class="p">(</span><span class="n">u</span><span class="p">,</span> <span class="n">selection</span><span class="o">=</span><span class="p">(</span><span class="n">selA</span><span class="p">,</span><span class="n">selB</span><span class="p">),</span> <span class="n">refgroup</span><span class="o">=</span><span class="p">(</span><span class="n">refA</span><span class="p">,</span><span class="n">refB</span><span class="p">),</span> <span class="n">radius</span><span class="o">=</span><span class="mf">8.0</span><span class="p">,</span> <span class="n">outfile</span><span class="o">=</span><span class="s">&quot;q.dat&quot;</span><span class="p">)</span>
</pre></div>
</div>
<p>If the groups do not match in length then a <tt class="xref py py-exc docutils literal"><span class="pre">ValueError</span></tt> is raised.</p>
<p>The analysis across the whole trajectory is performed with</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">CA1</span><span class="o">.</span><span class="n">run</span><span class="p">()</span>
</pre></div>
</div>
<p>Results are saved to <em>outfile</em> (<tt class="docutils literal"><span class="pre">framenumber</span> <span class="pre">q</span> <span class="pre">N</span></tt> per line) and
can also be plotted with</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">CA1</span><span class="o">.</span><span class="n">plot</span><span class="p">()</span>        <span class="c"># plots the time series q(t)</span>
<span class="n">CA1</span><span class="o">.</span><span class="n">plot_qavg</span><span class="p">()</span>   <span class="c"># plots the matrix of average contacts &lt;q&gt;</span>
</pre></div>
</div>
<p><strong>Description of computed values</strong> in the output file:</p>
<dl class="docutils">
<dt><em>N</em></dt>
<dd>number of native contacts</dd>
<dt><em>q</em></dt>
<dd>fraction of native contacts relative to the reference</dd>
</dl>
<p>Calculate native contacts within a group or between two groups.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Arguments :</th><td class="field-body"><dl class="first docutils">
<dt><em>topology</em></dt>
<dd><p class="first last">psf or pdb file</p>
</dd>
<dt><em>trajectory</em></dt>
<dd><p class="first last">dcd or xtc/trr file</p>
</dd>
<dt><em>universe</em></dt>
<dd><p class="first last">instead of a topology/trajectory combination, one can also supply
a <tt class="xref py py-class docutils literal"><span class="pre">MDAnalysis.Universe</span></tt></p>
</dd>
</dl>
</td>
</tr>
<tr class="field"><th class="field-name">Keywords :</th><td class="field-body"><dl class="first last docutils">
<dt><em>selection</em></dt>
<dd><p class="first last">selection string that determines which distances are calculated; if this
is a tuple or list with two entries then distances are calculated between
these two different groups [&#8220;name CA or name B*&#8221;]</p>
</dd>
<dt><em>refgroup</em></dt>
<dd><p class="first last">reference group, either a single <a class="reference internal" href="../core/AtomGroup.html#MDAnalysis.core.AtomGroup.AtomGroup" title="MDAnalysis.core.AtomGroup.AtomGroup"><tt class="xref py py-class docutils literal"><span class="pre">AtomGroup</span></tt></a>
(if there is only a single <em>selection</em>) or a list of two such groups.
The reference contacts are directly computed from <em>refgroup</em> and hence
the atoms in the reference group(s) must be equivalent to the ones produced
by the <em>selection</em> on the input trajectory.</p>
</dd>
<dt><em>radius</em></dt>
<dd><p class="first last">contacts are deemed any atoms within radius [8.0 A]</p>
</dd>
<dt><em>outfile</em></dt>
<dd><p class="first last">name of the output file; with the gz or bz2 suffix, a compressed
file is written. The average &lt;q&gt; is written to a second, gzipped
file that has the same name with &#8216;array&#8217; included. E.g. for the
default name &#8220;q1.dat.gz&#8221; the &lt;q&gt; file will be &#8220;q1.array.gz&#8221;. The
format is the matrix in column-row format, i.e. selection 1
residues are the columns and selection 2 residues are rows. The
file can be read with <a class="reference external" href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.loadtxt.html#numpy.loadtxt" title="(in NumPy v2.0.dev-ec56ee1)"><tt class="xref py py-func docutils literal"><span class="pre">numpy.loadtxt()</span></tt></a>.  [&#8220;q1.dat.gz&#8221;]</p>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
<p>The function calculates the percentage of native contacts q1
along a trajectory. &#8220;Contacts&#8221; are defined as the number of atoms
within <em>radius</em> of a given other atom. <em>q1</em> is the fraction of contacts
relative to the reference state 1 (typically the starting conformation
of the trajectory).</p>
<p>The timeseries is written to a file <em>outfile</em> and is also accessible as
the attribute <tt class="xref py py-attr docutils literal"><span class="pre">ContactAnalysis1.timeseries</span></tt>.</p>
<dl class="method">
<dt id="MDAnalysis.analysis.contacts.ContactAnalysis1.load">
<tt class="descclassname">ContactAnalysis1.</tt><tt class="descname">load</tt><big>(</big><em>filename</em><big>)</big><a class="headerlink" href="#MDAnalysis.analysis.contacts.ContactAnalysis1.load" title="Permalink to this definition">¶</a></dt>
<dd><p>Load the data file.</p>
</dd></dl>

<dl class="method">
<dt id="MDAnalysis.analysis.contacts.ContactAnalysis1.output_exists">
<tt class="descclassname">ContactAnalysis1.</tt><tt class="descname">output_exists</tt><big>(</big><em>force=False</em><big>)</big><a class="headerlink" href="#MDAnalysis.analysis.contacts.ContactAnalysis1.output_exists" title="Permalink to this definition">¶</a></dt>
<dd><p>Return True if default output file already exists.</p>
<p>Disable with force=True (will always return False)</p>
</dd></dl>

<dl class="method">
<dt id="MDAnalysis.analysis.contacts.ContactAnalysis1.plot">
<tt class="descclassname">ContactAnalysis1.</tt><tt class="descname">plot</tt><big>(</big><em>filename=None</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#MDAnalysis.analysis.contacts.ContactAnalysis1.plot" title="Permalink to this definition">¶</a></dt>
<dd><p>Plot q(t).</p>
<dl class="function">
<dt>
<tt class="descname">plot</tt><big>(</big><span class="optional">[</span><em>filename</em>, <em>...</em><span class="optional">]</span><big>)</big></dt>
<dd></dd></dl>

<p>If <em>filename</em> is supplied then the figure is also written to file (the
suffix determines the file type, e.g. pdf, png, eps, ...). All other
keyword arguments are passed on to <tt class="xref py py-func docutils literal"><span class="pre">pylab.plot()</span></tt>.</p>
</dd></dl>

<dl class="method">
<dt id="MDAnalysis.analysis.contacts.ContactAnalysis1.plot_qavg">
<tt class="descclassname">ContactAnalysis1.</tt><tt class="descname">plot_qavg</tt><big>(</big><em>filename=None</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#MDAnalysis.analysis.contacts.ContactAnalysis1.plot_qavg" title="Permalink to this definition">¶</a></dt>
<dd><p>Plot <tt class="xref py py-attr docutils literal"><span class="pre">ContactAnalysis1.qavg</span></tt>, the matrix of average native contacts.</p>
<dl class="function">
<dt>
<tt class="descname">plot_qavg</tt><big>(</big><span class="optional">[</span><em>filename</em>, <em>...</em><span class="optional">]</span><big>)</big></dt>
<dd></dd></dl>

<p>If <em>filename</em> is supplied then the figure is also written to file (the
suffix determines the file type, e.g. pdf, png, eps, ...). All other
keyword arguments are passed on to <tt class="xref py py-func docutils literal"><span class="pre">pylab.imshow()</span></tt>.</p>
</dd></dl>

<dl class="method">
<dt id="MDAnalysis.analysis.contacts.ContactAnalysis1.qN">
<tt class="descclassname">ContactAnalysis1.</tt><tt class="descname">qN</tt><big>(</big><em>q</em>, <em>out=None</em><big>)</big><a class="headerlink" href="#MDAnalysis.analysis.contacts.ContactAnalysis1.qN" title="Permalink to this definition">¶</a></dt>
<dd><p>Calculate native contacts relative to reference state.</p>
<p><em>q</em> is the matrix of contacts (e.g. <tt class="xref py py-attr docutils literal"><span class="pre">q</span></tt>).</p>
<p>If <em>out</em> is supplied as a pre-allocated array of the correct
shape then it is filled instead of allocating a new one in
order to increase performance.</p>
<p>This method is typically only used internally.</p>
</dd></dl>

<dl class="method">
<dt id="MDAnalysis.analysis.contacts.ContactAnalysis1.qarray">
<tt class="descclassname">ContactAnalysis1.</tt><tt class="descname">qarray</tt><big>(</big><em>d</em>, <em>out=None</em><big>)</big><a class="headerlink" href="#MDAnalysis.analysis.contacts.ContactAnalysis1.qarray" title="Permalink to this definition">¶</a></dt>
<dd><p>Return distance array with True for contacts.</p>
<p><em>d</em> is the matrix of distances. The method uses the value of
<tt class="xref py py-attr docutils literal"><span class="pre">ContactAnalysis1.radius</span></tt> to determine if a <tt class="docutils literal"><span class="pre">distance</span> <span class="pre">&lt;</span> <span class="pre">radius</span></tt>
is considered a contact.</p>
<p>If <em>out</em> is supplied as a pre-allocated array of the correct
shape then it is filled instead of allocating a new one in
order to increase performance.</p>
<p>This method is typically only used internally.</p>
</dd></dl>

<dl class="method">
<dt id="MDAnalysis.analysis.contacts.ContactAnalysis1.run">
<tt class="descclassname">ContactAnalysis1.</tt><tt class="descname">run</tt><big>(</big><em>store=True</em>, <em>force=False</em><big>)</big><a class="headerlink" href="#MDAnalysis.analysis.contacts.ContactAnalysis1.run" title="Permalink to this definition">¶</a></dt>
<dd><p>Analyze trajectory and produce timeseries.</p>
<p>Stores results in <tt class="xref py py-attr docutils literal"><span class="pre">ContactAnalysis1.timeseries</span></tt> (if store=True)
and writes them to a data file. The average q is written to a second
data file.</p>
</dd></dl>

</dd></dl>

</div>
</div>


          </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="distances.html" title="3.3. Distance analysis — MDAnalysis.distances"
             >next</a> |</li>
        <li class="right" >
          <a href="align.html" title="3.1. Coordinate fitting and alignment — MDAnalysis.analysis.align"
             >previous</a> |</li>
        <li><a href="../../index.html">MDAnalysis v0.7.5-devel documentation</a> &raquo;</li>
          <li><a href="../analysis_modules.html" >3. Analysis modules</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2005-2011, Naveen Michaud-Agrawal, Elizabeth J. Denning, Joshua Adelman,
    Christian Beckstein (logo), David Caplan, Jan Domański, Philip Fowler,
    Joseph Goose, Benjamin Hall, Danny Parton, Tyler Reddy, Paul Rigor,
    and Oliver Beckstein.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.7.
    </div>
  </body>
</html>